package com.example.eos.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.example.eos.tool.GlobalParam;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.groups.Default;
import java.util.Date;

/**
 * 用户信息
 */
public class User {
    @NotNull(message = "用户id不能为空", groups = GroupB.class)
    @Length(min = 32,max = 32, message = "用户id格式错误", groups = GroupB.class)
    private String userid;

    @NotNull(message = "手机号不能为空", groups = GroupA.class)
    @Pattern(regexp = "1[0-9]{10}",message = "手机号格式错误", groups = GroupA.class)
    private String phone;

    @NotNull(message = "密码不能为空", groups = GroupA.class)
    @Length(min = 32,max = 32, message = "用户密码格式错误", groups = GroupA.class)
    private String password;

    @NotNull(message = "用户名不能为空", groups = Default.class)
    @Length(min = 1,max = 10, message = "用户名格式错误", groups = Default.class)
    private String username;

    @NotNull(message = "姓名不能为空", groups = Default.class)
    @Length(min = 1,max = 10, message = "姓名格式错误", groups = Default.class)
    private String name;

    @NotNull(message = "性别不能为空", groups = Default.class)
    @Pattern(regexp = "[男女]", message = "性别格式错误", groups = Default.class)
    private String sex;

    private Integer labelnum;

    private Integer fllownum;

    private Integer fansnum;

    private Integer publishnum;

    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private Date creattime;

    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private Date lasttime;

    private Boolean exist;

    private String rolename;

    public User(){}

    public User(User user){
        this.userid = GlobalParam.getUUID();
        this.phone = user.phone;
        this.password = user.password;
        this.username = user.username;
        this.name = user.name;
        this.sex = user.sex;
        this.labelnum = 0;
        this.fllownum = 0;
        this.fansnum = 0;
        this.publishnum = 0;
        this.creattime = GlobalParam.getTime();
        this.lasttime = this.creattime;
        this.exist = true;
    }

    @Override
    public String toString() {
        return "User{" +
                "userid='" + userid + '\'' +
                ", phone='" + phone + '\'' +
                ", password='" + password + '\'' +
                ", username='" + username + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", labelnum=" + labelnum +
                ", fllownum=" + fllownum +
                ", fansnum=" + fansnum +
                ", publishnum=" + publishnum +
                ", creattime=" + creattime +
                ", lasttime=" + lasttime +
                ", exist=" + exist +
                '}';
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid == null ? null : userid.trim();
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone == null ? null : phone.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex == null ? null : sex.trim();
    }

    public Integer getLabelnum() {
        return labelnum;
    }

    public void setLabelnum(Integer labelnum) {
        this.labelnum = labelnum;
    }

    public Integer getFllownum() {
        return fllownum;
    }

    public void setFllownum(Integer fllownum) {
        this.fllownum = fllownum;
    }

    public Integer getFansnum() {
        return fansnum;
    }

    public void setFansnum(Integer fansnum) {
        this.fansnum = fansnum;
    }

    public Integer getPublishnum() {
        return publishnum;
    }

    public void setPublishnum(Integer publishnum) {
        this.publishnum = publishnum;
    }

    public Date getCreattime() {
        return creattime;
    }

    public void setCreattime(Date creattime) {
        this.creattime = creattime;
    }

    public Date getLasttime() {
        return lasttime;
    }

    public void setLasttime(Date lasttime) {
        this.lasttime = lasttime;
    }

    public Boolean getExist() {
        return exist;
    }

    public void setExist(Boolean exist) {
        this.exist = exist;
    }

    public String getRolename() {
        return rolename;
    }

    public void setRolename(String rolename) {
        this.rolename = rolename == null ? null : rolename.trim();
    }
}